home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoWriteSmallObj.c < prev   
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.8 KB  |  227 lines

  1. /*
  2.  *   $RCSfile: undoWriteSmallObj.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "logaction.h"
  62. #include "openlog.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_intfuncs.h"
  68. #include "util_funcs.h"
  69. #include "thread_globals.h"
  70. #include "bf_globals.h"
  71. #include "trans_globals.h"
  72. #include "sm_macro.h"
  73. #ifdef INIT_LRC_IS_LSN
  74. #    include "log_globals.h"
  75. #endif
  76.  
  77.  void
  78. undoWriteSmallObj (
  79.  
  80.     LOGRECORDHDR        *recordHeader 
  81. )
  82. {
  83.  
  84.     GROUPLINK            *groupLink;
  85.     SLOTTEDPAGE            *slottedPage;
  86.     char                *oldData;
  87.     int                    oldDataSize;
  88.     PID                    *pid;
  89.     WRITEINFO           *writeInfo;
  90.     FULLWRITEINFO       *fullWriteInfo;
  91.     PAGESLOT            *slotPtr;
  92.     SMALLOBJ            *objPtr;
  93.     LOGRECORDINFO       recordInfo;
  94. #ifdef INIT_LRC_IS_LSN
  95.     LRC                 tempLRC;
  96.     LRC                 *lrc = &tempLRC;
  97. #else
  98.     LRC                 *lrc;
  99. #endif /* INIT_LRC_IS_LSN; */
  100.     LSN                    lsn;
  101.     FORCEMARK            forceMark;
  102.     BOOL                actionDone;    /* Indicates whether the action
  103.                                        was ever performed on the page */
  104.     INIT_MISSING_UPDATE_INFO( Active->transRec );
  105.  
  106.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  107.  
  108.     /* get a pointer to the page for the record */
  109.     pid = &(recordHeader->actionPid);
  110.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  111.  
  112.  
  113.  
  114.     if (recordHeader->action == LOG_ACTION_WRITE_SMALL_OBJ) {
  115.         /* get pointer to oid, header info */
  116.         writeInfo = (WRITEINFO*) GET_LOG_IMAGE(recordHeader, 0);
  117.  
  118.         /* get a pointer to the old data and its size in the record */
  119.         oldData = GET_LOG_IMAGE(recordHeader, 2);
  120.         oldDataSize = GET_LOG_IMAGE_SIZE(recordHeader, 2);
  121.     } else {
  122.         SM_ASSERT(LEVEL_3, recordHeader->action == LOG_ACTION_WRITE_SMALL_OBJ_ND);
  123.         /* get pointer to oid, header info */
  124.         fullWriteInfo = (FULLWRITEINFO*) GET_LOG_IMAGE(recordHeader, 0);
  125.         writeInfo = &(fullWriteInfo->common);
  126.  
  127.         /* get a pointer to the old data and its size in the record */
  128.         oldData = GET_LOG_IMAGE(recordHeader, 1);
  129.         oldDataSize = fullWriteInfo->size;
  130.         SM_ASSERT(LEVEL_3, fullWriteInfo->size == GET_LOG_IMAGE_SIZE(recordHeader, 1));
  131.     }
  132.  
  133.     /* read in the page */
  134.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, SLOTTED_PAGE2SIZE, BF_SEM)) == NULL) {
  135.         SM_ERROR(TYPE_FATAL, Active->errno);
  136.     }
  137.     groupLink->pageHash->pageType = PAGE_SLOTTED;
  138.  
  139.     /* get a pointer to the slotted page */
  140.     slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  141.     if (CHECK_SLOTTED_MAGIC(slottedPage)) {
  142.         SM_ERROR(TYPE_FATAL, Active->errno);
  143.     }
  144.  
  145.     /* See if the action was actually done */ 
  146.      actionDone = compareLRC(&(recordHeader->actionLRC), &(slottedPage->header.lrc) ) <= 0;
  147.     
  148.     /*
  149.      *    it is possible that the action 
  150.      *    never made it to the page on the server, so missing update
  151.      *    information may need to be recorded
  152.      *
  153.      *    Process any missing updates, and return a pointer to
  154.      *    the lrc to increment.  This will either be the lrc on the
  155.      *    slotted page, or the lrc in the missingUpdatePageTable
  156.      */
  157.     RECORD_MISSING_UPDATE( actionDone, &lrc, missingUpdateInfo, pid,
  158.                          &(slottedPage->header.lrc),
  159.                          groupLink->pageHash, recordHeader, PAGE_SLOTTED);
  160.  
  161.     /* increment the lrc on the page */
  162.     GENERATE_LRC(lrc);
  163.  
  164.     /*
  165.      *    Log the undo write
  166.      */
  167.     if (recordHeader->action == LOG_ACTION_WRITE_SMALL_OBJ) {
  168.         recordInfo.action       = LOG_ACTION_WRITE_SMALL_OBJ;
  169.         recordInfo.imageCount   = 2;
  170.         recordInfo.imageSize[0] = sizeof(*writeInfo);
  171.         recordInfo.imageData[0] = (VOID *) writeInfo;
  172.         recordInfo.imageSize[1] = (unsigned short) oldDataSize;
  173.         recordInfo.imageData[1] = (VOID *) oldData;
  174.     } else {
  175.         recordInfo.action       = LOG_ACTION_WRITE_SMALL_OBJ_ND;
  176.         recordInfo.imageCount   = 1;
  177.         recordInfo.imageSize[0] = sizeof(*fullWriteInfo);
  178.         recordInfo.imageData[0] = (VOID *) fullWriteInfo;
  179.     }
  180.     recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  181.     recordInfo.actionPid    = pid;
  182.     recordInfo.actionLRC    = lrc;
  183.     recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  184.     recordInfo.flags        = NOFLAGS;
  185.  
  186.     /* write the record to the log */
  187.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  188.                               &lsn, NOFLAGS)) < 0)  {
  189.         SM_ERROR(TYPE_FATAL, Active->errno);
  190.     }
  191.  
  192.     /* mark the page dependency */
  193. #ifndef INIT_LRC_IS_LSN
  194.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  195. #endif
  196.  
  197.     /*
  198.      *    perform the undo, if the action was performed
  199.      */
  200.     if (actionDone) {
  201.  
  202. #ifdef INIT_LRC_IS_LSN
  203.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  204. #endif
  205.  
  206.         /*
  207.          *    Get a pointer to the slot and then the object
  208.          */
  209.         SM_ASSERT(LEVEL_3, writeInfo->slot < slottedPage->header.slotCount);
  210.         slotPtr = GETSLOTPTR(slottedPage, writeInfo->slot);
  211.         SM_ASSERT(LEVEL_3, writeInfo->unique == slotPtr->unique);
  212.         objPtr  = GETOBJECTPTR(slottedPage, slotPtr);
  213.  
  214.         SM_ASSERT(LEVEL_3, (objPtr->objectHdr.size > (writeInfo->start + oldDataSize - 1)) || (objPtr->objectHdr.properties & P_LARGEOBJ));
  215.         bcopy(oldData, objPtr->data + writeInfo->start, oldDataSize);
  216.     }
  217.  
  218.     /*
  219.      *    release the semaphore and unfix the page, dirty the page if
  220.      *    the action was done
  221.      */
  222.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  223.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  224.  
  225.     return;
  226. }
  227.